package com.xbongbong.pro.enums;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.ContactEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import lombok.Getter;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

@Getter
public enum ClueConverDefaultEnum {

    COMPANY_NAME(ClueEnum.COMPANY_NAME.getAttr(), CustomerManagementEnum.NAME.getAttr(), "", ""),
    CONTACT(ClueEnum.CONTACT.getAttr(), null, ContactEnum.NAME.getAttr(), null),
    SUB_TYPE(ClueEnum.PHONE.getAttr() + ".text_1", CustomerManagementEnum.PHONE.getAttr() + ".text_1", ContactEnum.PHONE.getAttr() + ".text_1", null),
    SUB_PHONE(ClueEnum.PHONE.getAttr() + ".text_2", CustomerManagementEnum.PHONE.getAttr() + ".text_2", ContactEnum.PHONE.getAttr() + ".text_2", null),
    LABEL(ClueEnum.LABEL.getAttr(), CustomerManagementEnum.LABEL.getAttr(), null, null),
    ADDRESS(ClueEnum.ADDRESS.getAttr(), CustomerManagementEnum.ADDRESS.getAttr(), ContactEnum.ADDRESS.getAttr(), null),
    OWNER_ID(ClueEnum.OWNER_ID.getAttr(), null, null, SalesOpportunityEnum.OWNER_ID.getAttr()),
    COUSERID(ClueEnum.COUSERID.getAttr(), null, null, SalesOpportunityEnum.COUSER_ID.getAttr()),
    MEMO(ClueEnum.MEMO.getAttr(), CustomerManagementEnum.MEMO.getAttr(), null, null),
    ;
    /**
     * 线索字段attr
     */
    private String clueAttr;

    /**
     * 客户字段attr
     */
    private String cusAttr;

    /**
     * 联系人字段attr
     */
    private String conAttr;
    /**
     * 机会字段attr
     */
    private String oppAttr;

    ClueConverDefaultEnum(String clueAttr, String cusAttr, String conAttr, String oppAttr) {
        this.clueAttr = clueAttr;
        this.cusAttr = cusAttr;
        this.conAttr = conAttr;
        this.oppAttr = oppAttr;
    }

    public static Map<String, String> getRelationAttrMap(Integer businessType) {
        Map<String, String> map = new LinkedHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
                for (ClueConverDefaultEnum defaultEnum : values()) {
                    if (Objects.nonNull(defaultEnum.getCusAttr())) {
                        map.put(defaultEnum.getClueAttr(), defaultEnum.getCusAttr());
                    }
                }
                break;
            case CONTACT:
                for (ClueConverDefaultEnum defaultEnum : values()) {
                    if (Objects.nonNull(defaultEnum.getConAttr())) {
                        map.put(defaultEnum.getClueAttr(), defaultEnum.getConAttr());
                    }
                }
                break;
            case SALES_OPPORTUNITY:
                for (ClueConverDefaultEnum defaultEnum : values()) {
                    if (Objects.nonNull(defaultEnum.getOppAttr())) {
                        map.put(defaultEnum.getClueAttr(), defaultEnum.getOppAttr());
                    }
                }
                break;
            default:
                break;
        }
        return map;
    }
}
